<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>班组记录（弃用）</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
	<div class="demoTable" style="padding:10px 0 0 15px">
    	班组名称
    	<div class="layui-inline">
        	<input class="layui-input" name="keyWord" id="keyWord" autocomplete="off">
    	</div> &nbsp; &nbsp; &nbsp; &nbsp;
    	<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
	</div>
	
	<table class="layui-hide" id="test" lay-filter="test"></table>
	
	<%-- <div id="formDiv" hidden>
	<form class="layui-form" id="addform">
		<input type="hidden" id="tid" name="tid">
		<label class="layui-form-label">排产单</label>
		<div class="layui-input-inline" style="width:300px">
			<select id="tname" name="production" class="layui-input" lay-search="" lay-verify="production">
				<option value="">请选择排产单</option>
				<c:forEach items="${listTeam }" var="team">
					<option value="${team.tname }">${team.tname }</option>
				</c:forEach>
			</select>
		</div><br><br>
		<label class="layui-form-label">班组名称</label>
		<div class="layui-input-inline" style="width:300px">
			<select id="tname" name="tname" class="layui-input" lay-search="" lay-verify="tname">
				<option value="">请选择班组</option>
				<c:forEach items="${listTeam }" var="team">
					<option value="${team.tname }">${team.tname }</option>
				</c:forEach>
			</select>
		</div><br><br>
		<label class="layui-form-label">人员</label><input lay-verify="pname" class="layui-input" type="text" id="pname" name="pname" style="width:300px"><br>
		<label class="layui-form-label">日期</label><input lay-verify="ttime" class="layui-input" type="text" id="ttime" name="ttime" style="width:300px"><br>
		<label class="layui-form-label">备注</label><input lay-verify="remarks" class="layui-input" type="text" id="remarks" name="remarks" style="width:300px"><br>
		<button class="layui-btn layui-btn-blue" lay-submit lay-filter="addform" style="margin-left:140px">立即提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</form>
</div> --%>

<script type="text/html" id="toolbarDemo">
</script>
	<!-- <div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div> -->
 
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
</script>
	<!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
              
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>

<script>
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var tnumber = $("#keyWord").val();
				table.reload('contenttable',{
					method:'get',
					where:{tname: tname}
				}); 
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/teamRecordMana/listPageTeamRecord.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '班组记录'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
	    	{type: 'checkbox', fixed: 'left'}
	    	,{field:'productionId', title:'排产单ID'}
	      	,{field:'tname', title:'班组名称'}
	      	,{field:'tnumber', title:'班组编号'}
	      	,{field:'ttime', title:'时间'}
	      	,{field:'pname', title:'人员'}
	      	,{field:'remarks', title:'备注'}
	      	,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件(搜索，批量删除)
	table.on('toolbar(test)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'delete':
	        	var data = checkStatus.data;
	        	var str = "";
	        	if(data.length==0){
	        		toastr.warning("请至少选择一条记录！");
	        	}
	        	for(var i=0;i<data.length;i++){
	        		str += data[i].tid;
	        		if(i != data.length-1){
	        			str += ",";
	        		}
	        	}
	        	layer.confirm('确定删除吗？', function(index){
	        		$.ajax({
				    	type:'post',
				    	url:'${pageContext.request.contextPath }/teamRecordMana/deleteTeamRecord.do',
				    	data:{"str" : str},
				    	success:function(data){
				    		if(data>0){
				    			toastr.success("删除成功！");
				    			location.reload();
				    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
									//关闭模态框
									// 父页面刷新
									window.location.reload();  
								},2000); 
				    		}else{
				    			toastr.warning("删除失败！");
				    			location.reload();
				    		}
				    	}
				    }); 
	        	});
	      	break;
	      	case 'select':
	      		console.log(obj)
	      	break;
	    };
	});
  
	//监听行工具事件(编辑，删除)
	table.on('tool(test)', function(obj){
		var data = obj.data;
		if(obj.event === 'del'){
		  layer.confirm('确定删除吗？', function(index){
		    var tid = obj.data.tid;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/teamRecordMana/deleteTeamRecord.do',
		    	data:{"str":tid},
		    	dataType : "json",
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		} else if(obj.event === 'edit'){
			layer.open({
				  type: 1 		//Page层类型
				  ,area: ['40%', '70%'] //宽  高
				  ,title: '修改编辑'
				  ,shade: 0.1 	//遮罩透明度
				  ,maxmin: true //允许全屏最小化
				  ,anim: 1 		//0-6的动画形式，-1不开启
				  ,content: $('#formDiv')
				  ,success: function () {
					//回显表单数据
					for(var i=0;i<Object.entries(data).length;i++) {
						var id = '#' + Object.entries(data)[i][0];
						var text = Object.entries(data)[i][1];
						$(id).val(text);
					}
					form.render();
				  }	
				  ,end: function () {
				  	var formDiv = document.getElementById('formDiv');
				  	formDiv.style.display = '';
			  	  }
			});
		}
	});
	/**
     * 表单校验
     */
    form.verify({
    	//value：表单的值、item：表单的DOM对象
    	 tname: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	tnumber: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	foreman: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	ename: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	ecode: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	pname: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	ttime: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	remarks: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    });
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$.ajax({
			url : '${pageContext.request.contextPath }/teamRecordMana/saveTeamRecord.do',
			data : $('#addform').serialize(),
			type : "post",
			dataType : "json",
			}).done(
				function(res) {
					if (res > 0) {
						toastr.success('保存成功！');
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
					}
				}
			).fail(
				function(res) {
					layer.close(1);
					toastr.error('保存失败！');
				}
			)
			return false;
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

</script>
</body>
</html>